package com.zyh.zhuantike;

public class Test2 {
    public static void main(String[] args) {
        /*
        找素数，判断101-200之间有多少个素数
         */
        /*for (int i = 101; i < 201; i++) {
            isPrime(i);
        }*/
        int count = 0;
        for (int i = 101; i < 201; i++) {
            boolean suShu = isPrime2(i);
            if (suShu) {
                System.out.print(i + " ");
                count++;
            }
        }
        System.out.println();
        System.out.println("101-200之间有" + count + "个素数.");

    }

    public static void isPrime(int n) {
        boolean flag = true;
        int count = 0;
        for (int i = 2; i < n; i++) {
            if (n % i == 0) {
                flag = false;
                break;
            }
        }
        if (flag) {
            System.out.println(n + "是素数");
            count++;
        } else {
            System.out.println(n + "不是素数");
        }
    }

    public static boolean isPrime2(int n) {
        boolean flag = true;
        for (int i = 2; i < n; i++) {
            if (n % i == 0) {
                flag = false;
                break;
            }
        }
        return flag;
    }
}
